import instance from "@/utils/requestUtils";

export default {
    name: "login",
    data() {
        return {
            baseStr: '',
            loginForm: {
                uuid: '',
                code: "",
                username: "",
                password: ""
            }

        }
    },
    methods: {
        async getCode() {
            this.loginForm.uuid = this.guid();
            this.baseStr = await instance.get(`common/getCode?uuid=${this.loginForm.uuid}`)
        },

        guid() {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
                var r = Math.random() * 16 | 0,
                    v = c == 'x' ? r : (r & 0x3 | 0x8);
                return v.toString(16);
            });
        },
        async doLogin() {
            let result = await instance.post(`common/doLogin`, this.loginForm)
            localStorage.setItem("token", result);
            this.getAdminInfo();

        },

        async getAdminInfo() {
            let result = await instance.get(`common/getAdminInfo`);
            localStorage.setItem("menus", JSON.stringify(result.menus))
            localStorage.setItem("btn", JSON.stringify(result.btn))
            this.$router.push('/index')
        }
    },
    created() {
        this.getCode();
    }

}
